package com.huawei.appgallery.forum.cards.card;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.cards.bean.ForumHorizonBean;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import o.azb;
import o.bsy.c;
import o.bsy.e;
import o.cgz;
import o.chy;
import o.ContentManager;
import o.eix;
import o.eiy;
import o.MinimumFactory;
import o.evx;

public abstract class ForumHorizonCard extends ForumCard {
    private CSSRule ʼ;
    protected LinearLayoutManager ˊ;
    protected View ˋ;
    protected eix ˎ = new eix();
    protected chy ˏ;
    protected RecyclerView ॱ;
    protected androidx.recyclerview.widget.RecyclerView.a ॱॱ;

    protected abstract class a extends androidx.recyclerview.widget.RecyclerView.a<a> {
        final /* synthetic */ ForumHorizonCard ॱ;

        protected class a extends s {
            protected View ॱˋ;
            final /* synthetic */ a ᐝॱ;

            public a(a aVar, View view) {
                this.ᐝॱ = aVar;
                super(view);
                this.ॱˋ = view;
            }
        }

        protected abstract a ˊ(ViewGroup viewGroup, int i);

        protected abstract void ˎ(a aVar, int i);

        protected a(ForumHorizonCard forumHorizonCard) {
            this.ॱ = forumHorizonCard;
        }

        @NonNull
        public /* synthetic */ s ˎ(@NonNull ViewGroup viewGroup, int i) {
            return ॱ(viewGroup, i);
        }

        public /* synthetic */ void ॱ(@NonNull s sVar, int i) {
            ˊ((a) sVar, i);
        }

        @NonNull
        public a ॱ(@NonNull ViewGroup viewGroup, int i) {
            a ˊ = ˊ(viewGroup, i);
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                ˊ.ॱˋ.setLayoutDirection(1);
            }
            this.ॱ.ˎ(ˊ.ॱˋ, this.ॱ.ʼ);
            return ˊ;
        }

        public void ˊ(@NonNull a aVar, int i) {
            ˎ(aVar, i);
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) aVar.ॱˋ.getLayoutParams();
            if (marginLayoutParams != null) {
                ˎ(i, marginLayoutParams);
                aVar.ॱˋ.setLayoutParams(marginLayoutParams);
            }
        }

        private void ˎ(int i, MarginLayoutParams marginLayoutParams) {
            marginLayoutParams.setMarginEnd(0);
            if (i == 0) {
                marginLayoutParams.setMarginStart(this.ॱ.ˎ.ॱ());
                return;
            }
            if (i == ˏ() - 1) {
                marginLayoutParams.setMarginEnd(this.ॱ.ˎ.ॱ());
            }
            marginLayoutParams.setMarginStart(this.ॱ.ˎ.ॱॱ());
        }
    }

    protected abstract void ˎ();

    protected abstract androidx.recyclerview.widget.RecyclerView.a ᐝ();

    public /* synthetic */ cgz ˏ(View view) {
        return ˎ(view);
    }

    public ForumHorizonCard(Context context) {
        super(context);
        this.ˎ.ˎ(azb.ˊ(context) - context.getResources().getDimensionPixelSize(e.ॱˎ));
        this.ˎ.ᐝ(context.getResources().getDimensionPixelSize(e.ॱˎ));
        ˎ();
    }

    public void ˏ(CSSRule cSSRule) {
        this.ʼ = cSSRule;
    }

    public View ʻ() {
        return this.ˋ;
    }

    public ForumCard ˎ(View view) {
        ʽ(view);
        this.ˋ = view.findViewById(c.ॱꓸ);
        ॱ((RecyclerView) view.findViewById(c.ˋ));
        this.ॱॱ = ᐝ();
        this.ˊ = new LinearLayoutManager(view.getContext(), 0, false);
        ॱॱ().setLayoutManager(this.ˊ);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            ॱॱ().setLayoutDirection(0);
            this.ˊ.ˊ(true);
        }
        ॱॱ().setAdapter(this.ॱॱ);
        new eiy().ˏ(ॱॱ());
        this.ॱ.ॱ(new n(this) {
            final /* synthetic */ ForumHorizonCard ˋ;

            {
                this.ˋ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                if (i == 0) {
                    CardBean ˌ = this.ˋ.ˌ();
                    if (ˌ instanceof ForumHorizonBean) {
                        ForumHorizonBean forumHorizonBean = (ForumHorizonBean) ˌ;
                        Boolean valueOf = Boolean.valueOf(this.ˋ.ˊ.ॱˎ() == this.ˋ.ˊ.ˌ() + -1);
                        int ॱˎ = this.ˋ.ˊ.ॱˎ();
                        this.ˋ.ˎ.ॱॱ(this.ˋ.ˊ.ॱˊ());
                        this.ˋ.ˎ.ʻ(this.ˋ.ॱॱ().getLeft());
                        if (valueOf.booleanValue()) {
                            forumHorizonBean.ˏ(ॱˎ);
                            forumHorizonBean.ˎ(this.ˋ.ˎ.ʻ());
                            return;
                        }
                        forumHorizonBean.ˎ(this.ˋ.ˎ.ʻ());
                        forumHorizonBean.ˏ(this.ˋ.ˎ.ᐝ());
                    }
                }
            }
        });
        return this;
    }

    public RecyclerView ॱॱ() {
        return this.ॱ;
    }

    public void ॱ(RecyclerView recyclerView) {
        this.ॱ = recyclerView;
    }

    public void ॱ(final chy o_chy) {
        this.ˏ = o_chy;
        ʻ().setOnClickListener(new evx(this) {
            final /* synthetic */ ForumHorizonCard ˏ;

            public void ˋ(View view) {
                o_chy.ˏ(9, this.ˏ);
            }
        });
    }

    protected void ˋ(CardBean cardBean) {
        ((TextView) this.ˊˋ.findViewById(c.ˏ)).setText(cardBean.v_());
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        ˋ(cardBean);
        if (cardBean instanceof ForumHorizonBean) {
            ForumHorizonBean forumHorizonBean = (ForumHorizonBean) cardBean;
            this.ˊ.ॱ(forumHorizonBean.N_(), forumHorizonBean.ʽ());
        }
        this.ॱॱ.ˊ();
    }

    private void ˎ(View view, CSSRule cSSRule) {
        if (cSSRule != null) {
            CSSView.wrap(view, cSSRule).render();
        }
    }
}
